home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / collectDishesChar.lua < prev    next >
Text File  |  2004-01-29  |  8KB  |  306 lines

  1. -- dish collecting character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         --local dishwasher = getStateObjectFromID(msg.sender);
  7.         local dishwasher = getStoredOrSender("dishwasher", msg)
  8.         storeStateObject("dishwasher", dishwasher);
  9.         
  10.         freeHands(getParent());
  11.                         
  12.     end )
  13.     
  14.     onExit(function(msg)
  15.         local dishwasher = retrieveStateObject("dishwasher");
  16.         if (dishwasher) then
  17.             getParent().unlockActionPoints(dishwasher);
  18.             removeStateObject("dishwasher");
  19.         end;        
  20.  
  21.         local table = retrieveStateObject("table");
  22.         if (table) then
  23.             print("onExit table removed");
  24.             getParent().unlockActionPoints(table);
  25.             removeStateObject("table");
  26.         else        
  27.             print("onExit table NOT removed");
  28.         end
  29.         
  30.         local dish = retrieveStateObject("dish");
  31.         if (dish) then
  32.             print("onExit dish removed");
  33.             removeStateObject("dish");
  34.         else        
  35.             print("onExit dish NOT removed");
  36.         end
  37.     end )
  38.     
  39.     state("findDishes")
  40.     
  41.         onEnter(function(msg)
  42.             print("findDishes onEnter");
  43.             local table, actionPoint, dishFound = getNextTableWithDishes(getParent());
  44.             if (not table or testCancel()) then
  45.                 print("no table with dishes found or cannot reach table");
  46.  
  47.                 if (dishFound) then
  48.                     print(" --> dish was found but reachable");
  49.                     -- dish was found but reachable
  50.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);            
  51.                 end
  52.                 
  53. --                local dishHeap = getParent().getRightHeldObject();
  54. --                if (dishHeap) then setState("gotoDishwasher"); return end;
  55.                 setState("gotoDishwasher");
  56. --                exitStateMachine();
  57.                 return
  58.             end
  59.             
  60.             storeStateObject("table", table);
  61.             storeData("actionPointName", actionPoint.getName());
  62.                         
  63.             if (walkToPointImmediate(actionPoint)) then
  64.             
  65.                 enterStateMachine("subwalk.walk");
  66.  
  67.             else
  68.             
  69.                 print("no path found");
  70.                 getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);            
  71.                 
  72. --                local dishHeap = getParent().getRightHeldObject();
  73. --                if (dishHeap) then setState("gotoDishwasher"); return end
  74.                 setState("gotoDishwasher");
  75. --                exitStateMachine();
  76.                 return
  77.             end
  78.                         
  79.         end )
  80.         
  81.         
  82.         onReturn(function(msg)
  83.             print("dish collecting character findDishes onReturn");
  84.             setState("takePlate");
  85.         end )
  86.         
  87.     
  88.     state("takePlate")
  89.     
  90.         onEnter(function(msg)
  91.             print("takePlate onEnter");
  92.         
  93.             local table = retrieveStateObject("table"); 
  94.             local actionPointName = retrieveData("actionPointName");
  95.  
  96.             if (table) then
  97.                 -- table does exist
  98.                 if (getParent().isActionPointLocked(table, actionPointName)) then
  99.                     -- action point is locked
  100.                     print("takePlate action point is locked");
  101.                     setState("findDishes");
  102.                     return
  103.                 else
  104.                     getParent().lockActionPoint(table, actionPointName);
  105.                 end
  106.             else
  107.                 -- table does not exist anymore
  108.                 print("takePlate table does not exist anymore");
  109.                 setState("findDishes");
  110.                 return
  111.             end
  112.             
  113.             local dishes = getChildrenWithBehavior(table, "dish");
  114.             local dish = dishes[1];
  115.             if (dish) then
  116.                 storeStateObject("dish", dish);
  117.                 startAnimation("takePlate");
  118.                 sendDelayedMsgThis("grabPlate", 360);
  119.                 sendDelayedMsgThis("dropPlate", 840);
  120.             else
  121.                 setState("findDishes");
  122.                 return
  123.             end
  124.             
  125.         end )
  126.         
  127.         
  128.         onExit(function(msg)
  129.         
  130.             local table = retrieveStateObject("table");
  131.             if (table) then
  132.                 print("takePlate onExit table removed");
  133.                 getParent().unlockActionPoints(table);
  134.                 removeStateObject("table");
  135.             else        
  136.                 print("takePlate onExit table NOT removed");
  137.             end
  138.             
  139.             local dish = retrieveStateObject("dish");
  140.             if (dish) then
  141.                 print("takePlate onExit dish removed");
  142.                 removeStateObject("dish");
  143.             else        
  144.                 print("takePlate onExit dish NOT removed");
  145.             end
  146.             
  147.             
  148.         end )
  149.  
  150.         
  151.         onMsg("grabPlate", function(msg)
  152. --            local dish = retrieveStateObject("dish");
  153. --            removeStateObject("dish");
  154. --            dish.moveGameObject(getParent());
  155. --            getParent().attachLeftObjectHolder(dish);
  156.  
  157.             local dish = retrieveStateObject("dish");
  158.             removeStateObject("dish");
  159.             dish.deleteGameObject();
  160.             
  161.             dish = getParent().loadGameObject("StandardGO","plate");
  162.             getParent().attachLeftObjectHolder(dish);            
  163.         end )    
  164.         
  165.         onMsg("dropPlate", function(msg)
  166.         
  167.             local numDishes = retrieveData("numDishes", 0);
  168.             storeData("numDishes", numDishes+1);
  169.         
  170.             local dish = getParent().getLeftHeldObject();
  171.             getParent().detachLeftObjectHolder();
  172.             
  173.             getParent().playSound("stackPlates");
  174.             
  175.             local dishHeap = getParent().getRightHeldObject();
  176.             if (dishHeap) then
  177.                 print("right hand full, delete plate");
  178.                 dish.deleteGameObject();
  179.             else
  180.                 print("move to right hand");
  181.                 getParent().attachRightObjectHolder(dish);
  182.                 getParent().handSO.setPose("rightHandHoldPlate");
  183.             end
  184.         end )    
  185.          
  186.         onMsg("end", function(msg)
  187.             setState("findDishes");
  188.         end )    
  189.         
  190.  
  191.     state("gotoDishwasher")
  192.     
  193.         onEnter(function(msg)
  194.             print("gotoDishwasher");
  195.             local character = getParent();
  196.             local numDishes = retrieveData("numDishes", 0);
  197.             
  198.             local dishwasher = retrieveStateObject("dishwasher");
  199.             
  200.             
  201.             if ((numDishes < 1) and (getDish(dishwasher) < 1)) then
  202.                 freeHands(getParent());
  203.                 exitStateMachine();
  204.                 return
  205.             end
  206.             
  207.             --local actionPoint = getParent().getFreeActionPoint(dishwasher, {"load","washHands"});
  208.             local actionPoint = getParent().getClosestFreeActionPoint(getParent(), dishwasher, {"load","washHands"});
  209.             if (actionPoint) then
  210.                 if (walkToPointImmediate(actionPoint)) then
  211.                     enterStateMachine("subwalk.walk");
  212.                     return
  213.                 else
  214.                     print("no path to dishwasher found");
  215.                     character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  216.                     sendMsg("emoThink", character.walkSO);
  217.                 end
  218.             else
  219.                 print("no load dishwasher action point found");
  220.                 character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  221.                 sendMsg("emoThink", character.walkSO);
  222.             end
  223.             
  224.             freeHands(getParent());
  225.             exitStateMachine();
  226.                         
  227.         end )
  228.  
  229.         onReturn(function(msg)
  230.             -- returned from subwalk to dishwasher/sink
  231. --            print("dish collecting character gotoDishwasher onReturn");
  232. --            local wsoContext = StateMachineContext();
  233. --            wsoContext.storeData("numDishes", retrieveData("numDishes", 0));
  234. --            queueStateMachine(retrieveData("washState"), retrieveStateObject("dishwasher"), wsoContext);
  235. --            exitStateMachine();
  236.             
  237.             setState("atDishwasher");
  238.         end )
  239.  
  240.  
  241.  
  242.  
  243.  
  244.     state("atDishwasher")
  245.     
  246.         onEnter(function(msg)
  247.             print("atDishwasher entering " .. retrieveData("washState"));
  248.             enterStateMachine(retrieveData("washState"));
  249.                         
  250.         end )
  251.  
  252.         onReturn(function(msg)
  253.             -- returned from  dishwasher/sink
  254.             print("dish collecting character atDishwasher onReturn");
  255.             exitStateMachine();
  256.         end )
  257.  
  258.         
  259.         
  260. --    state("gotoDishwasher")
  261. --    
  262. --        onEnter(function(msg)
  263. --            print("gotoDishwasher");
  264. --            local character = getParent();
  265. --            local numDishes = retrieveData("numDishes", 0);
  266. --            
  267. --            if (numDishes < 1) then
  268. --                freeHands(getParent());
  269. --                exitStateMachine();
  270. --                return
  271. --            end
  272. --            
  273. --            local dishwasher = retrieveStateObject("dishwasher");
  274. --            --local actionPoint = getParent().getFreeActionPoint(dishwasher, {"load","washHands"});
  275. --            local actionPoint = getParent().getClosestFreeActionPoint(getParent(), dishwasher, {"load","washHands"});
  276. --            if (actionPoint) then
  277. --                if (walkToActionPoint(actionPoint)) then
  278. --                    -- create state machine contexts
  279. --                    local wsoContext = StateMachineContext();
  280. --                    wsoContext.storeData("numDishes", numDishes);
  281. --                    queueStateMachine(retrieveData("washState"), dishwasher, wsoContext);
  282. --                    --queueStateMachine("dishwasherChar.load", dishwasher);
  283. --                    exitStateMachine();
  284. --                    return
  285. --                else
  286. --                    print("no path to dishwasher found");
  287. --                    character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  288. --                    sendMsg("emoThink", character.walkSO);
  289. --                end
  290. --            else
  291. --                print("no load dishwasher action point found");
  292. --                character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  293. --                sendMsg("emoThink", character.walkSO);
  294. --            end
  295. --            
  296. ----            local dishHeap = getParent().getRightHeldObject();
  297. ----            if (dishHeap) then dishHeap.deleteGameObject(); end
  298. ----            getParent().detachRightObjectHolder();
  299. --            freeHands(getParent());
  300. --            exitStateMachine();
  301. --                        
  302. --        end )
  303.             
  304.                 
  305. endStateMachine()
  306.